package com.jacobson.huobi.common.expansion

import com.jacobson.huobi.Constants
import com.jacobson.huobi.common.constants.AlarmStatusConstant
import com.jacobson.huobi.common.constants.AlarmTypeConstant
import com.jacobson.huobi.entities.AlarmInfo
import com.jacobson.huobi.entities.SymbolInfo
import com.jacobson.huobi.utils.SettingProperties

fun SymbolInfo.isAlarm(): Boolean {
//    return (alarmH1.status == AlarmStatusConstant.VALUE_ALARM_NEW
//            || alarmH4.status == AlarmStatusConstant.VALUE_ALARM_NEW
//            || alarmH12.status == AlarmStatusConstant.VALUE_ALARM_NEW
//            || alarmDay.status == AlarmStatusConstant.VALUE_ALARM_NEW)&& (this.volume / Constants.SYMBOL_VOLUME_UNIT >= SettingProperties.getMinVolumeValue()!!.toDouble())
//            || alarmH1.status == AlarmStatusConstant.VALUE_ALARM
//            || alarmH4.status == AlarmStatusConstant.VALUE_ALARM
//            || alarmH12.status == AlarmStatusConstant.VALUE_ALARM
//            || alarmDay.status == AlarmStatusConstant.VALUE_ALARM
    return this.volume / Constants.SYMBOL_VOLUME_UNIT >= SettingProperties.getMinVolumeValue()!!.toDouble()
}

fun SymbolInfo.isAlarmWithStatus(): Boolean {
    return (alarmH1.status == AlarmStatusConstant.VALUE_ALARM_NEW
            || alarmH4.status == AlarmStatusConstant.VALUE_ALARM_NEW
            || alarmH12.status == AlarmStatusConstant.VALUE_ALARM_NEW
            || alarmDay.status == AlarmStatusConstant.VALUE_ALARM_NEW)&& isAlarm()
//            || alarmH1.status == AlarmStatusConstant.VALUE_ALARM
//            || alarmH4.status == AlarmStatusConstant.VALUE_ALARM
//            || alarmH12.status == AlarmStatusConstant.VALUE_ALARM
//            || alarmDay.status == AlarmStatusConstant.VALUE_ALARM
}

/**
 * 是否是买入报警
 * TODO 暂时只检查1小时
 */
fun SymbolInfo.isBuyAlarm(): Boolean {
    return isAlarm() && alarmH1.isBuyAlarm()
}

/**
 * 是否是卖出报警
 * TODO 暂时只检查1小时
 */
fun SymbolInfo.isSellAlarm(): Boolean {
    return isAlarm() && alarmH1.isSellAlarm()
}

fun AlarmInfo.isBuyAlarm() = this.type in arrayOf(
    // 启动
    AlarmTypeConstant.VALUE_START_1,
    // 站稳
    AlarmTypeConstant.VALUE_STAND_1,
    AlarmTypeConstant.VALUE_STAND_2
)

fun AlarmInfo.isSellAlarm() = this.type in arrayOf(
    // 破线
    AlarmTypeConstant.VALUE_BREAK_1,
    AlarmTypeConstant.VALUE_BREAK_3,
    AlarmTypeConstant.VALUE_BREAK_4,
    AlarmTypeConstant.VALUE_BREAK_5,
    AlarmTypeConstant.VALUE_BREAK_6,
    AlarmTypeConstant.VALUE_BREAK_7,
    // 失败
    AlarmTypeConstant.VALUE_FAILED_1,
    // 结束
    AlarmTypeConstant.VALUE_END_1,
    AlarmTypeConstant.VALUE_END_2
)